//===================================================================================
// $$
//
// Coder: Code Milker v1.0
// 0 - EntityName
// 1 - Properties
//===================================================================================


namespace App.Domain.Handlers {
    using System;
    using App.Data;
    using App.Domain.Contracts;
    using App.Domain.Models;

    public class CreateJobCategory {
        private readonly IJobCategoryRepository _jobCategoryRepository;

        public CreateJobCategory(IJobCategoryRepository jobCategoryRepository) {
            _jobCategoryRepository = jobCategoryRepository;
        }

        public void Execute(Guid userId, ICreateJobCategoryCommand jobCategoryForm) {
            if (jobCategoryForm == null)
                throw new ArgumentNullException("jobCategoryForm");

            try {
                var jobCategory = jobCategoryForm.ConvertToEntity();
                _jobCategoryRepository.Create(jobCategory);
            }
            catch (InvalidOperationException ex) {
                throw new BusinessServicesException("UnableToCreateVehicleExceptionMessage", ex);
            }
        }
    }
}
